package gwu.android;

import java.util.ArrayList;
import java.util.Iterator;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;

public class DisplayArticleScores extends Activity {
	private LinearLayout mScoreLayout;

	protected void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.display_scores);
		setTitle("Article Scores");
		
		mScoreLayout = (LinearLayout) findViewById(R.id.scoreLayout);
        Bundle extras = getIntent().getExtras();
        int correct = 0;
        int wrong = 0;

        ArrayList<Integer> scores = extras.getIntegerArrayList(WordItemsDbAdapter.KEY_SCORE);
        for(int i = 0; i < scores.size(); i++){
        	int score = scores.get(i);
        	TextView textBox = new TextView(this);
        	textBox.setText("Item #"+(i+1));
        	textBox.setLayoutParams(new LayoutParams(
        			LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        	if(score==1){
        		textBox.setTextColor(Color.GREEN);
        		correct++;
        	}
        	else if(score==-1){
        		textBox.setTextColor(Color.RED);
        		wrong++;
        	}
        	
        	mScoreLayout.addView(textBox);
        }
        TextView totalsBox = new TextView(this);
        totalsBox.setLayoutParams(new LayoutParams(
    			LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        totalsBox.setText("\nTotal Score");
        totalsBox.setTypeface(Typeface.DEFAULT_BOLD, 1);
        
        TextView correctBox = new TextView(this);
        correctBox.setLayoutParams(new LayoutParams(
    			LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        correctBox.setText("Correct: " + correct);
        correctBox.setTextColor(Color.GREEN);
        
        TextView wrongBox = new TextView(this);
        wrongBox.setLayoutParams(new LayoutParams(
    			LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        wrongBox.setText("Wrong: " + wrong);
        wrongBox.setTextColor(Color.RED);
        
        TextView unansweredBox = new TextView(this);
        unansweredBox.setLayoutParams(new LayoutParams(
    			LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        unansweredBox.setText("Unanswered: " + (scores.size()-correct-wrong));
        mScoreLayout.addView(totalsBox);
        mScoreLayout.addView(correctBox);
        mScoreLayout.addView(wrongBox);
        mScoreLayout.addView(unansweredBox);
        
        
	}
}
